package com.njtoyo.taxi.admin.rest.controller.local_service.commodity;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njtoyo.taxi.admin.aop.PermissionScope;
import com.njtoyo.taxi.admin.mapper.master.entity.local_service.LifeMerchantCommodityCategory;
import com.njtoyo.taxi.admin.rest.wrapper.local_service.platform.PlatformAddWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.local_service.platform.PlatformUpdateWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.local_service.platform.PlatformWrapper;
import com.njtoyo.taxi.admin.service.local_service.commodity.CategoryService;
import com.taxi.entity.common.RestResult;
import com.njtoyo.taxi.entity.backend.AdminUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;

@RestController
@Api(value = "商品管理", tags = "商品管理")
@RequestMapping("local-service/platform")
public class CategoryController {

    @Autowired
    private CategoryService platformService;

    @GetMapping("/all")
    @ApiOperation(value = "所有商品分类", notes = "所有商品分类,权限：")
    RestResult<List<LifeMerchantCommodityCategory>> all() {
        return platformService.all();
    }
    
    @GetMapping("")
    @ApiOperation(value = "商品分类列表", notes = "商品分类列表,权限：life_category_list")
    @PermissionScope(names = {"life_category_list"})
    RestResult<Page<LifeMerchantCommodityCategory>> getPage(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser,
                                                            @Valid PlatformWrapper wrapper) {
        return platformService.getPage(adminUser, wrapper);
    }

    @PostMapping("")
    @ApiOperation(value = "添加商品分类", notes = "life_category_add")
    @PermissionScope(names = {"life_category_add"})
    RestResult add(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser,
                   @Valid @RequestBody PlatformAddWrapper wrapper) {
        return platformService.add(adminUser, wrapper);
    }

    @PatchMapping("/{id}")
    @ApiOperation(value = "修改商品分类", notes = "life_category_update")
    @PermissionScope(names = {"life_category_update"})
    RestResult update(@PathVariable("id") Long id,
                      @Valid @RequestBody PlatformUpdateWrapper wrapper) {
        return platformService.update(id, wrapper);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除商品分类", notes = "life_category_delete")
    @PermissionScope(names = {"life_category_delete"})
    RestResult delete(@PathVariable("id") Long id) {
        return platformService.delete(id);
    }
}